/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;

import java.io.File;
import java.io.RandomAccessFile;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Random;

public class JavaApplication1 {

    private static void doAccess() {

        try {

            File file = new File("D:\\DemoRandomAccessFile.out");
            RandomAccessFile raf = new RandomAccessFile(file, "rw");

            // Read a character
            byte ch = raf.readByte();
            System.out.println("Read first character of file: " + (char) ch);

            // Now read the remaining portion of the line.
            // This will print out from where the file pointer is located
            // (just after the '+' character) and print all remaining characters
            // up until the end of line character.
            System.out.println("Read full line: " + raf.readLine());
            long last_append = raf.getFilePointer();
            byte[] b = new byte[(int)(raf.length()-last_append)];
            raf.read(b);
            raf.getChannel().truncate(last_append);
            raf.writeBytes("Ini append.\n");
            raf.write(b);
            // Seek to the end of file
            //raf.seek(file.length());

            // Append to the end of the file
            //raf.write(0x0A);
            //raf.writeBytes("This will complete the Demo");
            raf.close();

        } catch (IOException e) {
            System.out.println("IOException:");
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception {
        List<Integer> t = new ArrayList<Integer>() {

            public boolean add(Integer mt) {
                int index = Collections.binarySearch(this, mt);
                if (index < 0) {
                    index = ~index;
                }
                super.add(index, mt);
                return true;
            }
        };
        ArrayList<Integer> a = new ArrayList<Integer>();
        Random r = new Random();
        for (int i=0;i<10000000;i++)
            t.add(r.nextInt());
        
        //for (int b : t)
        //    System.out.println(b);
        
    }
    
    public static void addTes(HashMap<Integer,ArrayList<Integer>> e, int a) {
        ArrayList<Integer> t = (ArrayList<Integer>) e.get(1);
        t.add(a);
    }
    
    public static void viewTes(HashMap<Integer,ArrayList<Integer>> e) {
        ArrayList<Integer> t = (ArrayList<Integer>) e.get(1);
        for (int a : t) {
            System.out.println("Integer "+a);
        }
    }
    
    
}
